import {
  TenantPageParams,
  TenantPageListGetResultModel,
  UploadRoleResult,
} from './model/systemModel';
import { defHttp } from '/@/utils/http/axios';
import { UploadFileParams } from '/#/axios';

enum Api {
  TenantPageList = '/admin/tenant/page',
  InfoTenant = '/admin/tenant',
  ADDTenant = '/admin/tenant/add',
  DelTenant = '/admin/tenant/del',
  UpdateTenant = '/admin/tenant/update',
  ExportTenant = '/admin/tenant/export',
  TempTenant = '/admin/sys-file/local/file/tenant.xlsx',
  ImportTenant = '/admin/tenant/import',
  GetConfigByKey = '/admin/sysTenantConfig/getByKey/',
  ProjectManagement = '/zkrq/projectState/list',
  ProjectManagementUser = '/zkrq/builder/list',
  ThirdPartyConfig = '/admin/sysTenantConfig/update/thirdPartyConfig',
  SmsConfig = '/admin/sysTenantConfig/update/sms',
  FilerServerConfig = '/admin/sysTenantConfig/update/filerServerConfig',
  SystemResourcesConfig = '/admin/sysTenantConfig/update/baseInfoConfig',
  EmailConfig = '/admin/sysTenantConfig/update/email',
  DingConfig = '/admin/sysTenantConfig/update/dingding',
}

export const saveThirdPartyConfigApi = (params: Indexable) =>
  defHttp.post<any>({ url: Api.ThirdPartyConfig, params });
export const saveSmsConfigApi = (params: Indexable) =>
  defHttp.post<any>({ url: Api.SmsConfig, params });
export const saveFilerServerConfigApi = (params: Indexable) =>
  defHttp.post<any>({ url: Api.FilerServerConfig, params });
export const saveFilerServerConfigSystemApi = (params: Indexable) =>
  defHttp.post<any>({ url: Api.SystemResourcesConfig, params });
export const saveEmailConfigApi = (params: Indexable) =>
  defHttp.post<any>({ url: Api.EmailConfig, params });
export const saveDingConfigApi = (params: Indexable) =>
  defHttp.post<any>({ url: Api.DingConfig, params });

export const getConfigByKeyApi = (key: string) =>
  defHttp.get<Indexable>({ url: Api.GetConfigByKey + key });
export const getProjectManagementUserApi = (params: Indexable) =>
  defHttp.post<any>({ url: Api.ProjectManagementUser, params });
export const getProjectManagementApi = (params: Indexable) =>
  defHttp.get<any>({ url: Api.ProjectManagement, params });

export const getTenantListByPage = (params?: TenantPageParams) =>
  defHttp.get<TenantPageListGetResultModel>({ url: Api.TenantPageList, params });

export const addTenantApi = (params: TenantPageParams) =>
  defHttp.post<any>({ url: Api.ADDTenant, params });

export const updateTenantApi = (params: TenantPageParams) =>
  defHttp.post<any>({ url: Api.UpdateTenant, params });

export const deleteTenantApi = (id: string) => defHttp.post<any>({ url: Api.DelTenant + '/' + id });
export const getTenantInfoApi = (id: string) =>
  defHttp.get<any>({ url: Api.InfoTenant + '/' + id });

export const exportTenantApi = () =>
  defHttp.get<any>(
    { url: Api.ExportTenant, responseType: 'arraybuffer' },
    { isTransformResponse: false },
  );

export const tempTenantApi = () =>
  defHttp.get<any>(
    { url: Api.TempTenant, responseType: 'arraybuffer' },
    { isTransformResponse: false },
  );

export function uploadTenantApi(
  params: UploadFileParams,
  onUploadProgress: (progressEvent: ProgressEvent) => void,
) {
  return defHttp.uploadFile<UploadRoleResult[]>(
    {
      url: Api.ImportTenant,
      onUploadProgress,
    },
    params,
  );
}
